package com.example.androidreviewapp.model

import android.content.ComponentName
import androidx.annotation.DrawableRes

@Suppress("ConvertSecondaryConstructorToPrimary")
class RunAppInfo {

    var name: String = ""
    var packageName = ""
    var isSystemApp = false

    var iconRes: Int = 0

    var componentName: ComponentName? = null
    var openIntentTask: Runnable? = null
    var activityComponentName: ComponentName? = null

    fun setComponentName(componentName: ComponentName): RunAppInfo {
        this.componentName = componentName
        return this
    }

    fun setActivityComponentName(componentName: ComponentName): RunAppInfo {
        this.activityComponentName = componentName
        return this
    }

    constructor(name: String, packageName: String) {
        this.name = name
        this.packageName = packageName
    }

    constructor(name: String, packageName: String, isSystemApp: Boolean) {
        this.name = name
        this.packageName = packageName
        this.isSystemApp = isSystemApp
    }

    fun setIconRes(@DrawableRes iconResource: Int): RunAppInfo {
        this.iconRes = iconResource
        return this
    }

    fun setLoadTask(runnable: Runnable): RunAppInfo {
        this.openIntentTask = runnable
        return this
    }

    fun addSelf(list: MutableList<RunAppInfo>) {
        if (!list.contains(this))
            list.add(this)
    }
}